package org.jdarwinbots.io.dsl;

import java.io.IOException;
import java.io.InputStream;

import org.antlr.runtime.ANTLRInputStream;
import org.antlr.runtime.CommonTokenStream;
import org.jdarwinbots.io.DNAReader;
import org.jdarwinbots.logic.DNA;

public class DarwinBotsGrammar2Reader implements DNAReader {

	@Override
	public DNA read(InputStream stream) throws IOException {

		DarwinBotsGrammar2Lexer lexer = new DarwinBotsGrammar2Lexer(new ANTLRInputStream(stream));
		CommonTokenStream tokens = new CommonTokenStream(lexer);

		DarwinBotsGrammar2Parser parser = new DarwinBotsGrammar2Parser(tokens);
		try {
			return parser.dna().value;

		} catch (Exception e) {
			throw new IOException(e);
		}

	}

}
